import { Module, ValidationPipe } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { APP_FILTER, APP_INTERCEPTOR, APP_GUARD, APP_PIPE } from '@nestjs/core';
import { TypeOrmModule } from '@nestjs/typeorm';

import { AppFilter } from './app.filter';
import { HeathCheckController } from './app.router';
import { AppInterceptor } from './app.interceptor';
import { UserModule } from './app/user/user.module';
import { UploadModule } from './app/upload/upload.module';
import { ProfileModule } from './app/profile/profile.module';
import { WxUserModule } from './wxuser/wxuser.module';

import { AuthGuard } from './auth/auth.guard';
import { env } from '../settings';
import { appDataSourceOptions } from '../typeorm-config';
import { WechatCheckModule } from './wechat-check/wechat-check.module';
import { CertificateModule } from './certificate/certificate.module';
import { MenuModule } from './menu/menu.module';
import { TopicModule } from './topic/topic.module';
import { CommentModule } from './comment/comment.module';
import { FavoriteModule } from './favorite/favorite.module';
import { DoctorModule } from './doctor/doctor.module';
import { MessageModule } from './message/message.module';

@Module({
  imports: [
    TypeOrmModule.forRoot(appDataSourceOptions),
    JwtModule.register({
      global: true,
      secret: env.JWT_SECRET,
      signOptions: { expiresIn: env.JWT_EXPIRES_IN },
    }),
    UserModule,
    UploadModule,
    ProfileModule,
    WxUserModule,
    WechatCheckModule,
    CertificateModule,
    MenuModule,
    TopicModule,
    CommentModule,
    FavoriteModule,
    DoctorModule,
    MessageModule,
  ],
  controllers: [HeathCheckController],
  providers: [
    {
      provide: APP_FILTER,
      useClass: AppFilter,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: AppInterceptor,
    },
    {
      provide: APP_GUARD,
      useClass: AuthGuard,
    },
    {
      provide: APP_PIPE,
      useClass: ValidationPipe,
    },
  ],
})
export class AppModule {}
